/**
 * Created by Administrator on 2017/5/22.
 */
/**
 * Created by Administrator on 2017/1/9.
 */
"use strict";

module.exports = function (sequelize, DataTypes) {
    var _model = sequelize.define("team", {
        teamid: {type: DataTypes.UUID, primaryKey: true, comment: '团队ID'}
        , userid: {
            type:DataTypes.STRING(100), comment: '用户ID', references: {
                model: sequelize.models.user
                , key:'userid'
            }
        }
        , picture: {type: DataTypes.STRING(150), comment: '团队头像'}
        , title: {type: DataTypes.STRING(50), allowNull: false, comment: '团队名称'}
        , info:{type:DataTypes.TEXT('long'),comment: '团队简介'}
        , ext: {type: DataTypes.TEXT("long"), comment: '扩展字段'}
    }, {
        indexes: [ {
            name: 'teamid'
            , fields: ['teamid']
        }, {
            name: 'userid'
            , fields: ['userid']
        }]
        , classMethods: {
            associate: function (models) {
                _model.belongsTo(models.user, {foreignKey: 'userid'});
                _model.hasMany(models.project, {foreignKey: 'teamid'});
                _model.hasMany(models.userProject, {foreignKey: 'teamid'});
            }
        }
    });
    return _model;
};